<template>
	<view class="content_view">	
		<topicon class="topicon" :iconWidth="100" :iconHeight="100" :startPostion="3" iconPath="../../../static/img/zhiding.png"
				 :marginBottom="10" :marginTop="60" :marginLeft="5" :marginRight="10" @tapIcon="tapIcon"
				></topicon>
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" :title="'监督检查任务详情'"></u-navbar>
		<uc-content :loading="loading">
			<view class="list-item">
				<view class="list-bottom">
					<view>任务名称:</view>
					<view>{{inspectData.title}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>检查人员:</view>
					<view>{{inspectData.inspectPersonName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>业主名称:</view>
					<view>{{inspectData.inspectEnterpriseName}}</view>
				</view>
			</view>
			<view class="list-item">
				<view class="list-bottom">
					<view>任务状态:</view>
					<view>{{inspectFormat(inspectData.status)}}</view>
				</view>
			</view>
			
			<uni-collapse accordion >
				<uni-collapse-item title="检查设备信息" class="collapse-title">	
					<uni-collapse accordion v-for="(value, key) in inspectData.ininspectItemModelList" :key="key" @change="collapseChange(value)">
						<uni-collapse-item :title="value.type + ' 已完成' + value.ywcsl + '个/需要完成' + value.xywcsl + '个'" class="collapse-title">
							<view class="list-item" v-for="(item,index) in value.list" :key="index">
								<view class="list-top" >
									<view class="list-left">设备名称: {{ item.name }}</view>
								</view> 
								<view class="list-center u-line-5">
									<view>地点: {{ item.address}}</view>
									<view>设备编码: {{item.code}}</view>
									<view >维保状态: {{statusFormat(item.status)}}</view>
									<view v-if="item.status == '01' && item.isvideo == '30' && item.mark" style="color: red;">
										{{item.mark}}
									</view>
									<view>
										<u-button v-if="item.status != '40'" @click="reportHiddenDanger(item.ucId, item.equipmentId)" :disabled="item.status == '40' || inspectData.status == '30'" type="primary" shape="square" style="width: 20%; float: right; margin-top: 5px; height: 30px;line-height: 30px; font-size: 12px;">上报隐患</u-button>
										<u-button v-if="(item.isvideo=='01' || item.isvideo=='10') && item.status != '40'" @click="recording(item)" :disabled="(item.status != '01' && item.isvideo=='01') || (item.status != '20' && item.isvideo=='10') || inspectData.status != '20'" type="primary" shape="square" style="width: 20%; float: right; margin-top: 5px; margin-right: 5px; height: 30px;line-height: 30px; font-size: 12px;">拍摄视频</u-button>	
										<u-button v-if="item.isvideo=='40' && item.status == '01'" @click="sbFire(item)" type="primary" shape="square" style="width: 20%; float: right; margin-top: 5px; margin-right: 5px; height: 30px;line-height: 30px; font-size: 12px;">非测试</u-button>
										<u-button v-if="item.isvideo=='40' && item.status == '01'" @click="wbCheck(item)" type="primary" shape="square" style="width: 20%; float: right; margin-top: 5px; margin-right: 5px; height: 30px;line-height: 30px; font-size: 12px;">测试</u-button>
									</view>
								</view>
								<view class="list-bottom">
								</view>
							</view>
						</uni-collapse-item>
					</uni-collapse>
				</uni-collapse-item>
			</uni-collapse>
			
		<view style="width:100%;margin-top: 15px; margin-left: 2.5%;">
			<view style="width:95%;">
				<u-button v-if="inspectData.status=='01'" @click="startTask(ucId)" type="primary" shape="square">确定任务</u-button>
				<u-button v-if="inspectData.status=='10'" @click="startExecute(ucId)" type="primary" shape="square">开始执行</u-button>
				<u-button v-if="inspectData.status=='20'" @click="stopTask(ucId)" type="primary" shape="square">暂停任务</u-button>
				<u-button v-if="inspectData.zs <= inspectData.zwcs && this.inspectData.status=='20' " @click="endTask(ucId)" type="primary" shape="square">结束任务</u-button>
			</view>
		</view>
		
		<uni-popup ref="popup" type="center">
		    <uni-popup-message style="width: 90%;margin-left: 5%;border-radius: 5px;" type="error" :message="tipMessage"></uni-popup-message>
		</uni-popup>
		
	</uc-content>
	</view>
</template>

<script>
	import topicon from '@/components/gwh-backTopIcon/gwh-backTopIcon.vue'
	import { mapGetters } from 'vuex'
	export default {
		components:{
			topicon
		},
		data() {
			return {
				inspectData: {},
				vinMaintenanceInfoDataList: [],
				statusOptions: [],
				inspectOptions: [],
				ucId:'',
				tipMessage: '',
				num:0,
				taskId:"",
				loading:false,
				title: ""
			}
		},
		onLoad(e) {
				this.ucId=e.ucId	
		},
		onShow() {
			this.initView(this.ucId)
		},
		computed:{
			...mapGetters(["refresh"])
		},
		watch: {
		    refresh: function (a, b) {
			  this.initView(this.ucId)
		    }
		},
		methods: {
			sbFire(item) {
				this.utils.request("/api/app/mainInfoData/wbFire", {
					ucId: item.equipmentId
				}, "post", "app", true).then(res => {
					this.initView()
				}).catch(error => {
					console.log(error)
				})
			},
			wbCheck(item) {
				this.utils.request("/api/app/mainInfoData/wbCheck", {
					ucId: item.equipmentId,
					modelId: item.ucId
				}, "post", "app", true).then(res => {
					this.initView()
				}).catch(error => {
					console.log(error)
				})
			},
			collapseChange(value) {
				this.vinMaintenanceInfoDataList = value.ininspectDataModelList
			},
			tapIcon(e){
				//此处为处理方法
				uni.pageScrollTo({
					duration:60,
					scrollTop:0
				})
			},
			statusFormat(data) {
				return this.selectDictLabel(this.statusOptions, data);
			},
			inspectFormat(data) {
				return this.selectDictLabel(this.inspectOptions, data);
			},
			initView(val) {
				this.loading = true
				this.inspectData = {}
				this.pageNum = 0
				this.getDataInfoVo(val)
				this.getDicts("equip_main_status").then(response => {
				    this.statusOptions = response.data.data;
				});
				
				this.getDicts("inspect_status").then(response => {
				    this.inspectOptions = response.data.data;
				});
			},
			recording(item){
				console.log(item)
				window.native.MaintenanceRecordVideo({ucId:item.ucId, maintenanceId: this.inspectData.ucId, menthd: 'jdjc'},res => {
					this.getDataInfoVo(this.ucId)
				});
			},
			getDataInfoVo(val) {
				this.utils.request("/api/app/inspect/" + val, {}, "get", "app", true).then(res => {
					this.inspectData = res.data.data
					this.loading=false
				}).catch(error => {
					this.loading=false
					console.log(error)
				})
			},
			stopTask(val) {
				this.utils.request("/api/app/inspect/stopTask", {ucId: val}, "post", "app", true).then(res => {
					this.getDataInfoVo(this.ucId)
					
				}).catch(error => {
					console.log(error)
				})
			},
			//开始任务
			startTask(val) {
				this.utils.request("/api/app/inspect/startTask", {ucId: val}, "post", "app", true).then(res => {
					this.getDataInfoVo(this.ucId)
					
				}).catch(error => {
					console.log(error)
				})
			},
			open() {
				this.$refs.popup.open('center')
			},
			close() {
				this.$refs.popup.close()
			},
			startExecute(val){
				this.utils.request("/api/app/inspect/startExecute", {ucId: val}, "post", "app", true).then(res => {
					console.log(res.data)
					if(res.data.code == 200){
					 	this.getDataInfoVo(this.ucId)
					} else{
						this.tipMessage = res.data.msg
						this.open()
					}
					this.getDataInfoVo(this.ucId)
				}).catch(error => {
					console.log(error)
				})
			},
			// 结束任务
			endTask(val){
				this.utils.request("/api/app/inspect/endTask", {ucId: val}, "post", "app", true).then(res => {
					this.getDataInfoVo(this.ucId)
				}).catch(error => {
					console.log(error)
				})
			},
			reportHiddenDanger(mainDataId, equipmentId){
				uni.navigateTo({
				    url: '/pages/index/workorder/maintenance/maintenanceHiddenDanger?ucId='+this.inspectData.ucId + "&equipmentId=" + equipmentId + "&mainDataId=" + mainDataId
				});
			},
			compileEq(){
				uni.navigateTo({
					url:'/pages/index/workorder/task/completeEqList?ucId='+this.inspectData.enterpriseId
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/uview-ui/libs/css/style.components.scss";
	
	.list-item {
		padding: 20rpx 40rpx;
		background-color: #fff;
		border-bottom: #999999 1px dashed ;
	
		.list-bottom {
			display: flex;
			margin-top: 10rpx;
			font-size: 28rpx;
			justify-content: space-between;
			color: #333;
		}
		.list-center {
			margin-top: 20rpx;
			font-size: 28rpx;
			color: #999999;
		}
	}
	.u-btn{
		margin-top: 5px;
		margin-bottom: 5px;
	}
	.collapse-title{
		padding: 0px 9px;
	}
	.uni-collapse-cell--open{
		background-color: #FFFFFF !important;
	}
	 .topicon >>> .icon{
	        border: #4CD964 2upx solid;
	    }
</style>
